<!DOCTYPE HTML>
<html>

<head>
      <meta charset="utf-8">
      <meta name="viewport" content="maximum-scale=1.0, minimum-scale=1.0, user-scalable=0, initial-scale=1.0, width=device-width" />
      <meta name="format-detection" content="telephone=no, email=no, date=no, address=no">
      <title>Hello APP</title>
      <link rel="stylesheet" type="text/css" href="../css/api.css" />
      <link rel="stylesheet" type="text/css" href="../css/style.css" />

    <style>
    .main{
      width:90%;
      height: auto;
      margin: 0 auto;
      background: rgb(243,243,243,0.5);

      /*padding-bottom: 4rem;*/
    }
    .main li{
      display: flex;
      background: white;
      background: #fff;
      padding: 0.8rem 0rem 0.5rem 0rem;
      margin-bottom: 0.5rem;
    }
    .main li img{
      width:2.5rem;
      height: 2.5rem;
    }
    .txt{
      width: 100%;
      padding-left: 0.2rem;
    }
    .txt p:nth-child(2){
      font-size: 0.8rem;
      color: #999999;
      padding-bottom: 0.5rem;
    }
    .txt p:nth-child(3){
      font-size: 0.8rem;
      color: #666666;
      padding-bottom: 0.5rem;
    }

    #img{
    display: flex;
    flex-wrap: wrap;
    flex: 1;
    }

    #imgs{
      width: 30%;
      height:7rem;
      margin-right: 0.5rem;
      margin-top: 0.5rem;
    }
    #imgs img{
      width: 100%;
      height: 100%;
    }
    input{
      width:75%;
      margin: 0 auto;
      height: 100%;
      background: rgb(242,242,242);
      padding: 0.8rem;
      border-radius: 1rem;
      outline: none;
    }

    .btn{
          font-size: 1.1rem;
          color:rgb(6,6,6)
    }
    .about{

      z-index: 99999;
      width: 20%;
      height: 2rem;
      color:white;
      line-height: 2rem;
      text-align: center;
      border-radius: 1rem;
      background: #40cccc;
      float: right;
    }
  .fl{
    float: left;
  }
  .fr{
    float: right;
  }
  .bottom{
    margin-top: 3rem;
    width: 100%;
    padding: 0%;
    border: 0.1rem solid #fff;
  }
  .cont_foot{
    width: 100%;
    height: 1.5rem;
    line-height: 1.5rem;
    padding: 0.8rem 0rem 0rem 0rem;
}
.footer_r{
  width:15%;
}
.footer_r p{
  font-size: 0.8rem;
  margin-top: 0.05rem;

}
.footer_img{
    width:32%;
    height: 7%;
    margin-left: 0.3rem;
    margin-top: 0.3rem;
  }
  .footer_img img{
    width: 100%;
    height: 100%;
  }
#image{
  width: 100%;
  height: 100%;
}
.headimg{
  width: 3rem;
  height: 3rem;
  border-radius: 2rem;
}
    </style>


</head>

<body>


    <ul class="main" id="postimg">


      <!-- er -->

    </ul>


    <script type="text/javascript" src="../script/jquery-1.8.3.js"></script>
    <script type="text/javascript" src="../script/api.js"></script>
    <script type="text/javascript" src="../script/common.js"></script>
</body>
<script>
var page = 1
var pagesize = 10
var ok = true
var userinfo = $api.getStorage('userinfo');
if(userinfo){
  uid=userinfo.id

}else{
  uid = 0
}
apiready = function() {

  api.addEventListener({
      name:'user_login',
      extra:{
          threshold:0
      }
  }, function(ret, err){
          userinfo=$api.getStorage('userinfo');
          uid=userinfo.id
        //	get_user()//获取用户数据
        page=1
        document.getElementById('postimg').innerHTML=''
        get_posting()

  });

  api.addEventListener({
      name:'user_register',
      extra:{
          threshold:0
      }
  }, function(ret, err){
          userinfo=$api.getStorage('userinfo');
          uid=userinfo.id
          //get_user()//获取用户数据
          page=1
          document.getElementById('postimg').innerHTML=''
          get_posting()
  });

  api.addEventListener({
      name:'user_out',
      extra:{
          threshold:0
      }
  }, function(ret, err){
          userinfo=$api.getStorage('userinfo');
          uid=0
        //	get_user()//获取用户数据
        page=1
        document.getElementById('postimg').innerHTML=''
        get_posting()
  });

  get_posting()//获取帖子列表

  api.addEventListener({
      name:'add_posting',
      extra:{
          threshold:0
      }
  }, function(ret, err){
      get_posting()
        //alert( JSON.stringify( ret ) );
  });

  api.addEventListener({
       　　name:'scrolltobottom',
           extra:{threshold:0}
       }, function(ret, err){
　　　　　　get_posting()
      });


      api.setRefreshHeaderInfo({
                           visible: true,
                           loadingImg: '../image/timg.gif',
                           bgColor: '#ccc',
                           textColor: '#fff',
                           textDown: '下拉刷新...',
                           textUp: '松开刷新...',
                           showTime: true
                       }, function(ret, err) {
                         ok = true
                         document.getElementById('postimg').innerHTML=''
                           page = 1;
                           get_posting()
               });

}
$(function () {
  $(".now").mousedown(function(event){

  event.stopPropagation();
  });
})
function gzs(self){
alert('阻止成功')

}

function get_posting() {
  if(ok==false){
    return false
  }
  var html = ''
  var obj = $api.byId('postimg');

  api.ajax({
      url: SITE_URL+'square_api/index/index',
      method: 'post',
      data: {
          values: {
              page: page,
              pagesize:pagesize,
              type:0,
              user_id:uid
          }
      }
  },function(ret, err){
      if (ret) {
        if(ret.error==200){

          for (var i = 0; i < ret.data.length; i++) {

            var dat = ret.data[i]
            var time = gettime(dat.add_time);


            html +='<li>'
              html +='<img src="'+dat.head_img+'">'
              html +='<div class="txt">'
              html +='<div class="now">'
                html +='<div class="fl"  onclick="opens('+dat.id+')">'
                  html +='<p>'+dat.nick_name+'</p>'
                  html +='<p>'+time+'</p>'
                html +='</div>'



                // if(dat.gz==1){
                //   html +='<div class="cont_imgs fr user'+dat.user_id+'" title="1" onclick="gz(this,'+dat.user_id+')" style="pointer-events: none;z-index:9999" >'
                //   html +='已关注'
                //   html +='</div>'
                // }else{
                //   html +='<div class="cont_imgs fr user'+dat.user_id+'" title="0" onclick="gz(this,'+dat.user_id+')" style="pointer-events: none;z-index:9999">'
                //   html +='关注'
                //   html +='</div>'
                // }

                if(dat.gz==1){
                  html +='<div class="fr about  user'+dat.user_id+'"  style="background-color:#D1D1D1" title="1" onclick="gz(this,'+dat.user_id+')">已关注</div>'

              }else{
                html +='<div class="fr about  user'+dat.user_id+'"  title="0" onclick="gz(this,'+dat.user_id+')" >关注</div>'
              }

              html +='</div>'
              html +='<div class="bottom"  onclick="opens('+dat.id+')">'
                html +='<p style="margin-left:0rem;width:100%;text-align:left;border:0.1rem solid #fff;padding:0rem;text-indent:0em;">'+dat.content+'</p>'
                html +='<div id="img">'
                if(dat.img_list.length>0&&dat.img_list!=''){
                  for (var is = 0; is < dat.img_list.length; is++) {
                    var img = dat.img_list[is]
                  html +='<div id="imgs"><img src="'+img+'" alt=""></div>'
                  }
                }


                html +='</div>'
              html +='</div>'
              html +='<div class="cont_foot"  onclick="opens('+dat.id+')">'
                html +='<p class="fl">浏览'+dat.browse+'次</p>'
                html +='<div class="footer_r fr">'
                  html +='<p class="fl">'+dat.pl+'</p>'
                  html +='<div class="footer_img fl"><img src="../image/a35.png" style="margin-top:0.1rem;" alt="" id="image"></div>'
                html +='</div>'
                html +='<div class="footer_r fr">'
                  // html +='<p class="fl">'+dat.sc+'</p>'
                  // html +='<div class="footer_img fl" style="width:32%;"><img src="../image/aaq.png" style="margin-bottom:0.4rem" alt="" id="image"></div>'
                html +='</div>'
              html +='</div>'
            html +='</div>'

            html +='</li>'














            // html +='<div class="cont_one" onclick="opens('+dat.id+')" >'
            // html +='<div class="cont_gai">'
            // html +='<div class="cont_top">'
            // html +='<div class="cont_img fl">'
            // html +='<img src="'+dat.head_img+'" alt="" class="headimg">'
            // html +='</div>'
            // html +='<div class="cont_p fl">'
            // html +='<p style="color:red;">'+dat.nick_name+'</p>'
            // html +='<p>'+time+'</p>'
            // html +='</div>'
            // html +='</div>'
            // if(dat.gz==1){
            //   html +='<div class="cont_imgs fr user'+dat.user_id+'" title="1" onclick="gz(this,'+dat.user_id+')" style="pointer-events: none;z-index:9999" >'
            //   html +='已关注'
            //   html +='</div>'
            // }else{
            //   html +='<div class="cont_imgs fr user'+dat.user_id+'" title="0" onclick="gz(this,'+dat.user_id+')" style="pointer-events: none;z-index:9999">'
            //   html +='关注'
            //   html +='</div>'
            // }
            //
            // html+='</div>'
            // html +='<div class="cont_cimgss">'
            // html +='<div class="conts_p">'+dat.content+'</div>'
            // html +='<div class="cont_cimg">'
            // if(dat.img_list){
            //   for (var is = 0; is < dat.img_list.length; is++) {
            //     var img = dat.img_list[is]
            //     html +='<div class="cimg_img">'
            //   html+='<img src="'+img+'" alt="">'
            //     html +='</div>'
            //   }
            // }
            // html+='</div>'
            // html +='</div>'
            // html +='<div class="cont_foot">'
            // html +='<p class="fl">浏览'+dat.browse+'次</p>'
            // html +='<div class="footer_r fr">'
            // html +='<p class="fl">'+dat.pl+'</p>'
            // html +='<div class="footer_img fl">'
            // html +='<img src="../image/a35.png" alt="">'
            // html +='</div>'
            // html +='</div>'
            // html +='<div class="footer_r fr">'
            // html +='<p class="fl">'+dat.sc+'</p>'
            // html +='<div class="footer_img fl">'
            // html +='<img src="../image/a35.png" alt="">'
            // html +='</div>'
            // html +='</div>'
            // html +='</div>'
            // html +='</div>'
          }

          $api.append(obj, html);
          page+=1

        }else{
          ok = false
          api.refreshHeaderLoadDone()
          msgcode('暂无更新帖子')
        }
        //  alert( JSON.stringify( ret ) );
        api.refreshHeaderLoadDone()
      } else {
        api.refreshHeaderLoadDone()
        msgcode('网络连接失败')
  //        alert( JSON.stringify( err ) );
      }
  });

}

function gz(self,tid) {
  if(!userinfo){
    login_at()
    return false
  }
  if(tid==userinfo.id){
    msgcode('暂不支持关注自己')
    return false
  }

  api.ajax({
      url: SITE_URL+'square_api/collection/gz',
      method: 'post',
      data: {
          values: {
              uid: userinfo.id,
              tid:tid,
              type:self.title
          }
      }
  },function(ret, err){
      if (ret) {
        if(ret.error==200){
          api.sendEvent({
              name: 'gz_user',

          });

          if(self.title==1){//取消管住宿
            msgcode('操作成功')
            $(".user"+tid).html('关注')
            $(".user"+tid).css('background-color','#40cccc')
            $(".user"+tid).attr('title','0')
          }else{//增加关注
            msgcode('操作成功')
            $(".user"+tid).css('background-color','#D1D1D1')
            $(".user"+tid).html('已关注')
            $(".user"+tid).attr('title','1')

          }
        }
        //  alert( JSON.stringify( ret ) );
      } else {
        msgcode('请检查网络连接')
          alert( JSON.stringify( err ) );
      }
  });


}

function opens(id) {
  // alert(id)
    api.openWin({
        name: 'posting',
        url: './posting.html',
        pageParam: {
                    id: id
                }
    });
}


</script>
</html>
